<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * 平台管理模块
 */
class Platforms extends Admin_Controller {
	
    function __construct()
    {
        parent::__construct();
        $this->load->model('plat_model');
        $this->load->model('plat_cpa_model');
        $this->load->model('users_model');
        $this->load->model('plat_invest_model');
        $this->load->model('plat_award_list_model');//
        $this->load->model('new_task_model');
        $this->load->model('account_model');
        $this->load->model('finance_list_model');
        $this->load->model('experience_list_model');
        $this->load->model('users_log_model');
        $this->plat_period = array(
            1 => '第一期',
            2 => '第二期',
            3 => '第三期'
        );
    }
    //理财平台AB类型列表
    public function index()
    {
        $where = array();
        $st = trim($_GET['st']);
        $key = trim($_GET['key']);
        if ($key != '') {
            if ($st == 1) {
                $con = '平台中文名称';
                $where['name_ch'] = $key;
            }
            if ($st == 2) {
                $con = '平台英文名称';
                $where['name_en'] = $key;
            }
        }
        if (trim($_GET['time-start']) && trim($_GET['time-end'])) {
            $time_start = strtotime($_GET['time-start']);
            $time_end = strtotime($_GET['time-end']) + 3600 * 24;
            $where['plat.create_time <= '] = $time_end;
            $where['plat.create_time >= '] = $time_start;
        }
        //分页
       $getcount = $this->plat_model->getPlatCount($where);
       $navigation_position = 'outside';
       $records_per_page = 10;
       $this->xpage->navigation_position(isset($navigation_position) && in_array($navigation_position, array('left', 'right')) ? $navigation_position : 'outside');
       //$this->xpage->reverse(true);
       $this->xpage->records($getcount);
       $this->xpage->records_per_page($records_per_page);
       $this->xpage->labels("<<", ">>");
       $list = $this->plat_model->getPlatList($where, (($this->xpage->get_page() - 1) * $records_per_page) ,$records_per_page);
       foreach ($list as $key =>$val){
           $award_array = $this->plat_model->get_user_award_list(array("plat_en"=>$val['name_en'],'is_add'=>0));
           if($val['name_en'] == "etongdai"){
               $award_array['award'] = $award_array['award'] - 31*20000;
               $award_array['true_award'] = $award_array['true_award'] - 31*200000;
           }
           $list[$key]['plat_type'] = $val['plat_type'] == 1 ? "AB类型" : "AC类型";
           $list[$key]['create_time'] = date("Y-m-d",$val['create_time']);
           $list[$key]['pay_amount'] = number_format($this->plat_model->get_pay_amount(array('name_en'=>$val['name_en'])));//剩余总金额
           $list[$key]['pay_amount_all'] = number_format($this->plat_model->get_pay_amount_all(array('name_en'=>$val['name_en'])));//预付总金额
           $list[$key]['user_amount'] =  $award_array['award'] ? number_format($award_array['award']) : 0;//用户返佣总额
           $list[$key]['user_amount_real'] =  $award_array['true_award'] ? number_format($award_array['true_award']) : 0;//平台实扣总额
           
       }
       
       //------------------
       $this->template->assign('stname', $st);
        $this->template->assign('keyname', trim($_GET['key']));
        $this->template->assign('conname', $con);
        $this->template->assign('time_start', trim($_GET['time-start']));
        $this->template->assign('time_end', trim($_GET['time-end']));
       $this->template->assign('Total',$getcount);
       $this->template->assign('showpage',$this->xpage->render(true));
        $this->template->assign('list',$list);
        $this->template->load('platforms/index');
    }
    //理财平台AB类型列表
    public function mlist()
    {
        $where = array();
        $st = trim($_GET['st']);
        $key = trim($_GET['key']);
        if ($key != '') {
            if ($st == 1) {
                $con = '平台中文名称';
                $where['name_ch'] = $key;
            }
            if ($st == 2) {
                $con = '平台英文名称';
                $where['name_en'] = $key;
            }
        }
        if (trim($_GET['time-start']) && trim($_GET['time-end'])) {
            $time_start = strtotime($_GET['time-start']);
            $time_end = strtotime($_GET['time-end']) + 3600 * 24;
            $where['plat.create_time <= '] = $time_end;
            $where['plat.create_time >= '] = $time_start;
        }
        //分页
       $getcount = $this->plat_model->getCount($where);
       $navigation_position = 'outside';
       $records_per_page = 10;
       $this->xpage->navigation_position(isset($navigation_position) && in_array($navigation_position, array('left', 'right')) ? $navigation_position : 'outside');
       //$this->xpage->reverse(true);
       $this->xpage->records($getcount);
       $this->xpage->records_per_page($records_per_page);
       $this->xpage->labels("<<", ">>");
       $list = $this->plat_model->getList($where, (($this->xpage->get_page() - 1) * $records_per_page) ,$records_per_page);
       foreach ($list as $key =>$val){
           $list[$key]['plat_type'] = $val['plat_type'] == 1 ? "AB类型" : "AC类型";
           $list[$key]['create_time'] = date("Y-m-d",$val['create_time']);
           $list[$key]['down_time'] = $val['down_time'] ? date("Y-m-d",$val['down_time']) : "";
           $list[$key]['pay_amount'] = number_format($val['pay_amount']);
           $list[$key]['period'] = $this->plat_period[$val['plat_period']];
       }
       //------------------
       $this->template->assign('stname', $st);
        $this->template->assign('keyname', trim($_GET['key']));
        $this->template->assign('conname', $con);
        $this->template->assign('time_start', trim($_GET['time-start']));
        $this->template->assign('time_end', trim($_GET['time-end']));
       $this->template->assign('Total',$getcount);
       $this->template->assign('showpage',$this->xpage->render(true));
        $this->template->assign('list',$list);
        $this->template->assign('segment_p','mlist');
        $this->template->load('platforms/p2p_list');
    }
    //添加理财平台
    public function p2p_add(){
        if($_POST){
            
            $plat_type = trim($_POST['plat_type']);//平台类型
            $name_ch = trim($_POST['name_ch']);//平台中文名称
            $name_en = trim($_POST['name_en']);//平台英文名称
            $total_person = trim($_POST['total_person']);//推广总人数
            $total_amount = trim($_POST['total_amount']);//推广总金额
            $plat_period = trim($_POST['plat_period']);//平台期数
            $exper_type = trim($_POST['exper_type']);//体验类型
            $access_key = trim($_POST['access_key']);//平台访问key
            $scale = trim($_POST['scale']);//平台结算系数
            $plat_interest = trim($_POST['plat_interest']);//平台利息
            $add_interest = trim($_POST['add_interest']);//弹溜溜加息
            $pay_amount = trim($_POST['pay_amount']);//平台预付款
            $website = trim($_POST['website']);//平台网站地址
            $max_award = trim($_POST['max_award']);//平台最大体验奖励
            $activity_tips = trim($_POST['activity_tips']);//平台活动标签
            $sort = trim($_POST['sort']);//排序
            $exper_time = trim($_POST['exper_time']);//平台体验时间
            $update_time = trim($_POST['update_time']);//平台奖励更新时间
            $receive_type = trim($_POST['receive_type']);//平台奖励发送类型
            $is_has_cpa = trim($_POST['is_has_cpa']);//是否体验第一步有注册奖励
            $is_index = trim($_POST['is_index']);//是否首页显示
            $is_show = trim($_POST['is_show']);//是否上线
            $is_hide = trim($_POST['is_hide']);//是否显示
            $is_fast_reg = trim($_POST['is_fast_reg']);//是否一键注册
            $is_fast_login = trim($_POST['is_fast_login']);//是否一键登录
            $is_fast_query = trim($_POST['is_fast_query']);//是否一键查询
            $logo_index = trim($_POST['logo_index']);//首页页logo
            $logo_list = trim($_POST['logo_list']);//列表页logo
            $logo_detail = trim($_POST['logo_detail']);//详情页logo
            $banner_img = trim($_POST['banner_img']);//详情页banner图
            $banner_link = trim($_POST['banner_link']);//详情页banner图片链接
            $description = trim($_POST['description']);//平台简介
            $require = trim($_POST['require']);//体验要求
            $raiders = trim($_POST['raiders']);//体验攻略
            $reg_link = trim($_POST['reg_link']);//一键注册接口链接
            $login_link = trim($_POST['login_link']);//一键登录接口链接
            $query_link = trim($_POST['query_link']);//一键查询接口链接
            $rules_ = explode( ';',$_POST['rules']);//体验规则
            
            /**************/
            //基本信息
            $base_data = array();
            $base_data['plat_en'] = $name_en;
            $base_data['company'] = trim($_POST['company']);//公司名称
            $base_data['reg_capital'] = trim($_POST['reg_capital']);//注册资本
            $base_data['ICP'] = trim($_POST['ICP']);//ICP备案信息
            $base_data['setup_time'] = trim($_POST['setup_time']);//成立时间
            $base_data['company_bg_type'] = trim($_POST['company_bg_type']);//公司背景
            $base_data['managed_funds'] = trim($_POST['managed_funds']);//托管资金
            $base_data['domain_name'] = trim($_POST['domain_name']);//域名
            $base_data['domain_time'] = trim($_POST['domain_time']);//备案时间
            $base_data['business_type'] = trim($_POST['business_type']);//业务类型
            $base_data['company_type'] = trim($_POST['company_type']);//公司类型
            $base_data['finance_info'] = trim($_POST['finance_info']);//融资信息
            $base_data['reg_address'] = trim($_POST['reg_address']);//注册地址
            /****************/
            
            $plat_data = array();
            $plat_data['name_ch'] = $name_ch;
            $plat_data['name_en'] = $name_en;
            $plat_data['total_person'] = $total_person;
            $plat_data['total_amount'] = $total_amount;
            $plat_data['plat_period'] = $plat_period;
            $plat_data['exper_type'] = $exper_type;
            $plat_data['plat_type'] = $plat_type;
            $plat_data['website'] = $website;
            $plat_data['access_key'] = $access_key;
            $plat_data['scale'] = $scale;
            $plat_data['pay_amount'] = $pay_amount;
            $plat_data['logo_index'] = $logo_index;
            $plat_data['logo_list'] = $logo_list;
            $plat_data['logo_detail'] = $logo_detail;
            $plat_data['max_award'] = $max_award;
            $plat_data['activity_tips'] = $activity_tips;
            $plat_data['is_has_cpa'] = $is_has_cpa;
            $plat_data['is_show'] = $is_show;
            $plat_data['is_index'] = $is_index;
            $plat_data['is_hide'] = $is_hide;
            $plat_data['is_fast_reg'] = $is_fast_reg;
            $plat_data['is_fast_login'] = $is_fast_login;
            $plat_data['is_fast_query'] = $is_fast_query;
            $plat_data['sort'] = $sort;
            $plat_data['create_time'] = time();
            
            //添加平台信息
            $plat_id = $this->plat_model->insert_plat($plat_data);
            if($plat_id){
                
                $this->plat_model->insert_baseinfo($base_data);
                
                $plat_info = $this->plat_model->get_info(array('plat_en'=>$name_en));
                if(!$plat_info){
                    $plat_info_data = array();
                    $plat_info_data['plat_en'] = $name_en;
                    $plat_info_data['plat_ch'] = $name_ch;
                    $plat_info_data['description'] = $description;
                    $plat_info_data['banner_img'] = $banner_img;
                    $plat_info_data['banner_img_index'] = $banner_img_index;
                    $plat_info_data['banner_link'] = $banner_link;
                    $plat_info_data['exper_time'] = $exper_time;
                    $plat_info_data['update_time'] = $update_time;
                    $plat_info_data['receive_type'] = $receive_type;
                    $plat_info_data['require'] = $require;
                    $plat_info_data['raiders'] = $raiders;
                    $plat_info_data['create_time'] = time();
                    //添加平台附加信息
                    $this->plat_model->insert_plat_info($plat_info_data);
                    
                    $plat_interface = array();
                    $plat_interface['plat_en'] = $name_en;
                    $plat_interface['reg_link'] = $reg_link;
                    $plat_interface['login_link'] = $login_link;
                    $plat_interface['query_link'] = $query_link;
                    //添加平台接口信息
                    $this->plat_model->insert_plat_interface($plat_interface);
                }
                if($rules_[0] != ""){
                    $rules = array();
                    foreach ($rules_ as $val){
                        $val = explode('|', $val);
                        $temp = array();
                        $temp['plat_id'] = $plat_id;
                        $temp['step'] = intval($val[0]);
                        $temp['rule'] = $val[1];
                        $temp['award'] = $val[2];
                        $temp['true_amount'] = $val[3];
                        $temp['exper'] = $val[4];
                        $temp['min_amount'] = $val[5];
                        $temp['max_amount'] = $val[6];
                        $temp['interest_desc'] = $val[7];
                        $temp['is_show'] = 1;
                        $rules[] = $temp;
                    }
                    //添加平台规则
                    $this->plat_model->insert_plat_rule($rules);
                }
                
                
                
                $mssage['info']	  = '添加成功';
                $mssage['status'] = 1;
                $mssage['url']	  = site_url('platforms/mlist');
                echo json_encode($mssage);exit;
                
            }else{
                $mssage['info']	  = '添加失败';
                $mssage['status'] = 0;
                $mssage['url']	  = site_url('platforms/mlist');
                echo json_encode($mssage);exit;
            }
        }
        $this->template->assign('bgtype',$this->bgType);
        $this->template->assign('segment_p','mlist');
        $this->template->load('platforms/p2p_add');
    }
       
    //生成平台蜜月
    function create_key(){
        if($_POST){
            $name_ch = trim($_POST['name_ch']);
            $name_en = trim($_POST['name_en']);
            $access_key = md5($name_en.$name_ch);
            $access_key = substr($access_key, 0,12);
            $access_key = strtolower($access_key);
            echo json_encode(array("key"=>$access_key));exit;
        }
    }
    
    //修改信息
    function p2p_edit(){
        if($_POST){
            $plat_id = trim($_POST['plat_id']);//平台类型
            $plat_type = trim($_POST['plat_type']);//平台类型
            $name_ch = trim($_POST['name_ch']);//平台中文名称
            $name_en = trim($_POST['name_en']);//平台英文名称
            $total_person = trim($_POST['total_person']);//推广总人数
            $total_amount = trim($_POST['total_amount']);//推广总金额
            $plat_period = trim($_POST['plat_period']);//平台期数
            $exper_type = trim($_POST['exper_type']);//体验类型
            $access_key = trim($_POST['access_key']);//平台访问key
            $scale = trim($_POST['scale']);//平台结算系数
            $plat_interest = trim($_POST['plat_interest']);//平台利息
            $add_interest = trim($_POST['add_interest']);//弹溜溜加息
            $pay_amount = trim($_POST['pay_amount']);//平台预付款
            $website = trim($_POST['website']);//平台网站地址
            $max_award = trim($_POST['max_award']);//平台最大体验奖励
            $activity_tips = trim($_POST['activity_tips']);//平台活动标签
            $sort = trim($_POST['sort']);//排序
            $exper_time = trim($_POST['exper_time']);//平台体验时间
            $update_time = trim($_POST['update_time']);//平台奖励更新时间
            $receive_type = trim($_POST['receive_type']);//平台奖励发送类型
            $is_has_cpa = trim($_POST['is_has_cpa']);//是否体验第一步有注册奖励
            $is_index = trim($_POST['is_index']);//是否首页显示
            $is_show = trim($_POST['is_show']);//是否上线
            $is_hide = trim($_POST['is_hide']);//是否显示
            $is_fast_reg = trim($_POST['is_fast_reg']);//是否一键注册
            $is_fast_login = trim($_POST['is_fast_login']);//是否一键登录
            $is_fast_query = trim($_POST['is_fast_query']);//是否一键查询
            $logo_index = trim($_POST['logo_index']);//首页页logo
            $logo_list = trim($_POST['logo_list']);//列表页logo
            $logo_detail = trim($_POST['logo_detail']);//详情页logo
            $banner_img = trim($_POST['banner_img']);//详情页banner图
            $banner_img_index = trim($_POST['banner_img_index']);//主页banner图
            $banner_link = trim($_POST['banner_link']);//详情页banner图片链接
            $description = trim($_POST['description']);//平台简介
            $require = trim($_POST['require']);//体验要求
            $raiders = trim($_POST['raiders']);//体验攻略
            $reg_link = trim($_POST['reg_link']);//一键注册接口链接
            $login_link = trim($_POST['login_link']);//一键登录接口链接
            $query_link = trim($_POST['query_link']);//一键查询接口链接
            $rules_ = explode( ';',$_POST['rules']);//体验规则
            
            /**************/
            //基本信息
            $base_data = array();
            $base_data['company'] = trim($_POST['company']);//公司名称
            $base_data['reg_capital'] = trim($_POST['reg_capital']);//注册资本
            $base_data['ICP'] = trim($_POST['ICP']);//ICP备案信息
            $base_data['setup_time'] = trim($_POST['setup_time']);//成立时间
            $base_data['company_bg_type'] = trim($_POST['company_bg_type']);//公司背景
            $base_data['managed_funds'] = trim($_POST['managed_funds']);//托管资金
            $base_data['domain_name'] = trim($_POST['domain_name']);//域名
            $base_data['domain_time'] = trim($_POST['domain_time']);//备案时间
            $base_data['business_type'] = trim($_POST['business_type']);//业务类型
            $base_data['company_type'] = trim($_POST['company_type']);//公司类型
            $base_data['finance_info'] = trim($_POST['finance_info']);//融资信息
            $base_data['reg_address'] = trim($_POST['reg_address']);//注册地址
            /****************/
            
            $plat_data = array();
            $plat_data['name_ch'] = $name_ch;
            $plat_data['name_en'] = $name_en;
            $plat_data['total_person'] = $total_person;
            $plat_data['total_amount'] = $total_amount;
            $plat_data['plat_period'] = $plat_period;
            $plat_data['exper_type'] = $exper_type;
            $plat_data['plat_type'] = $plat_type;
            $plat_data['website'] = $website;
            $plat_data['access_key'] = $access_key;
            $plat_data['scale'] = $scale;
            $plat_data['plat_interest'] = $plat_interest;
            $plat_data['add_interest'] = $add_interest;
            $plat_data['pay_amount'] = $pay_amount;
            $plat_data['logo_index'] = $logo_index;
            $plat_data['logo_list'] = $logo_list;
            $plat_data['logo_detail'] = $logo_detail;
            $plat_data['max_award'] = $max_award;
            $plat_data['activity_tips'] = $activity_tips;
            $plat_data['is_has_cpa'] = $is_has_cpa;
            $plat_data['is_show'] = $is_show;
            $plat_data['is_index'] = $is_index;
            $plat_data['is_hide'] = $is_hide;
            $plat_data['is_fast_reg'] = $is_fast_reg;
            $plat_data['is_fast_login'] = $is_fast_login;
            $plat_data['is_fast_query'] = $is_fast_query;
            $plat_data['sort'] = $sort;
            
            //更新平台信息
            $result = $this->plat_model->update_plat($plat_data,$plat_id);
            if($result){
                $flag = $this->plat_model->get_baseinfo(array("plat_en"=>$name_en));
                if($flag){
                    $this->plat_model->update_baseinfo($base_data,$name_en);
                }else{
                    $base_data['plat_en'] = $name_en;
                    $this->plat_model->insert_baseinfo($base_data);
                }
                
                $plat_info_data = array();
                $plat_info_data['plat_en'] = $name_en;
                $plat_info_data['plat_ch'] = $name_ch;
                $plat_info_data['description'] = $description;
                $plat_info_data['banner_img'] = $banner_img;
                $plat_info_data['banner_img_index'] = $banner_img_index;
                $plat_info_data['banner_link'] = $banner_link;
                $plat_info_data['exper_time'] = $exper_time;
                $plat_info_data['update_time'] = $update_time;
                $plat_info_data['receive_type'] = $receive_type;
                $plat_info_data['require'] = $require;
                $plat_info_data['raiders'] = $raiders;
                //更新平台附加信息
                $this->plat_model->update_plat_info($plat_info_data,$name_en);
                $plat_interface = array();
                $plat_interface['reg_link'] = $reg_link;
                $plat_interface['login_link'] = $login_link;
                $plat_interface['query_link'] = $query_link;
                //添加平台接口信息
                $this->plat_model->update_plat_interface($plat_interface,$name_en);
                if($rules_[0] != ""){
                    $this->plat_model->delete_plat_rule($plat_id);
                    $rules = array();
                    foreach ($rules_ as $val){
                        $val = explode('|', $val);
                        $temp = array();
                        $temp['plat_id'] = $plat_id;
                        $temp['step'] = intval($val[0]);
                        $temp['rule'] = $val[1];
                        $temp['award'] = $val[2];
                        $temp['true_amount'] = $val[3];
                        $temp['exper'] = $val[4];
                        $temp['min_amount'] = $val[5];
                        $temp['max_amount'] = $val[6];
                        $temp['is_show'] = $val[7];
                        $temp['interest_desc'] = $val[8];
                        $rules[] = $temp;
                    }
                    //添加平台规则
                    $this->plat_model->insert_plat_rule($rules);
                }
                
                
                $mssage['info']	  = '修改成功';
                $mssage['status'] = 1;
                $mssage['url']	  = site_url('platforms/mlist');
                echo json_encode($mssage);exit;
                
            }else{
                $mssage['info']	  = '修改失败';
                $mssage['status'] = 0;
                $mssage['url']	  = site_url('platforms/mlist');
                echo json_encode($mssage);exit;
            }
        }
        $id = trim($_GET['id']);
        if(!id){
            redirect('platforms/mlist');
        }
        $item = $this->plat_model->get_plat_info(array('plat.id'=>$id));
        $interface = $this->plat_model->get_plat_interface(array('plat_en'=>$item['name_en']));
        $baseinfo = $this->plat_model->get_baseinfo(array('plat_en'=>$item['name_en']));
        $item['reg_link'] = $interface['reg_link'];
        $item['login_link'] = $interface['login_link'];
        $item['query_link'] = $interface['query_link'];
        //获取体验规则
        $rule = $this->plat_model->get_plat_rules(array('plat_id'=>$id));
        if($rule){
            $str_rule = "";
            foreach ($rule as $key=> $val){
                if($key == 0){
                    $str_rule = $str_rule.$val['step']."|".$val['rule']."|".$val['award']."|".$val['true_amount']."|".$val['exper']."|".$val['min_amount']."|".$val['max_amount']."|".$val['is_show'].'|'.$val['interest_desc'];;
                }else{
                    $str_rule = $str_rule.";".$val['step']."|".$val['rule']."|".$val['award']."|".$val['true_amount']."|".$val['exper']."|".$val['min_amount']."|".$val['max_amount']."|".$val['is_show'].'|'.$val['interest_desc'];;
                }

            }
            $item['rules'] = $str_rule;
        }
        $this->template->assign('item',$item);
        $this->template->assign('baseinfo',$baseinfo);
        $this->template->assign('bgtype',  $this->bgType);
        $this->template->assign('segment_p','mlist');
        $this->template->load('platforms/p2p_edit');
    }
    //设置理财平台是否显示
    function setindex(){
        if($_GET){
            $mssage = array();
            $plat_id	   = trim($_GET['id']);
            $is_index = trim($_GET['is_index']);
            $data = array();
            $data['is_index'] = $is_index;
            $result = $this->plat_model->update_plat($data,$plat_id);
            if($result){
                update_cache("plat");
                if($is_index==1){
                    $mssage['info']	  = '启用成功';
                }else{
                    $mssage['info']	  = '禁用成功';
                }
                $mssage['status'] = 1;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }else{
                $mssage['info']	  = '操作失败';
                $mssage['status'] = 0;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
       }

    }	
    }
    
    //设置理财平台是否下线
    function setshow(){
        if($_GET){
            $mssage = array();
            $plat_id	   = trim($_GET['id']);
            $is_show = trim($_GET['is_show']);
            $data = array();
            $data['is_show'] = $is_show;
            $result = $this->plat_model->update_plat($data,$plat_id);
            if($result){
                if($is_show==1){
                    $mssage['info']	  = '启用成功';
                }else{
                    $mssage['info']	  = '禁用成功';
                }
                $mssage['status'] = 1;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }else{
                $mssage['info']	  = '操作失败';
                $mssage['status'] = 0;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }
        }	
    }
    
    //设置理财平台加息模式
    function setmode(){
        if($_GET){
            $mssage = array();
            $plat_id	   = trim($_GET['id']);
            $is_interest_mode = trim($_GET['mode']);
            $data = array();
            $data['is_interest_mode'] = $is_interest_mode;
            if($is_interest_mode == 0){
                $data['is_interest_mode'] = 0;
            }
            $result = $this->plat_model->update_plat($data,$plat_id);
            if($result){
                if($is_interest_mode==1){
                    $mssage['info']	  = '成功设置';
                }else{
                    $mssage['info']	  = '成功取消';
                }
                $mssage['status'] = 1;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }else{
                $mssage['info']	  = '操作失败';
                $mssage['status'] = 0;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }

        }	
    }
    
    //设置理财平台是否下线
    function setonline(){
        if($_GET){
            $mssage = array();
            $plat_id	   = trim($_GET['id']);
            $is_online = trim($_GET['is_online']);
            $data = array();
            $data['is_online'] = $is_online;
            if($is_online == 0){
                $data['is_mobile'] = 0;
            }
            $result = $this->plat_model->update_plat($data,$plat_id);
            if($result){
                if($is_hide==1){
                    $mssage['info']	  = '显示成功';
                }else{
                    $mssage['info']	  = '隐藏成功';
                }
                $mssage['status'] = 1;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }else{
                $mssage['info']	  = '操作失败';
                $mssage['status'] = 0;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }

        }	
    }
    
    //设置理财平台是否在手机上显示
    function setmobile(){
        if($_GET){
            $mssage = array();
            $plat_id	   = trim($_GET['id']);
            $is_mobile = trim($_GET['is_mobile']);
            $data = array();
            $data['is_mobile'] = $is_mobile;
            $result = $this->plat_model->update_plat($data,$plat_id);
            if($result){
                if($is_mobile==1){
                    $mssage['info']	  = '显示成功';
                }else{
                    $mssage['info']	  = '隐藏成功';
                }
                $mssage['status'] = 1;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }else{
                $mssage['info']	  = '操作失败';
                $mssage['status'] = 0;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }

        }	
    }
    
    //AC平台用户绑定记录
    function bindac(){
        $where = array();
        $st = trim($_GET['st']);
        $key = trim($_GET['key']);
        if ($key != '') {
            if ($st == 1) {
                $con = '平台中文名称';
                $plat = $this->plat_model->get(array('name_ch'=>$key));
                $where['plat_id'] = $plat['id'];
            }
            if ($st == 2) {
                $con = '平台英文名称';
                $plat = $this->plat_model->get(array('name_en'=>$key));
                $where['plat_id'] = $plat['id'];
            }
            if ($st == 3) {
                $con = '用户名';
                $user = $this->users_model->get_user_by_username($key);
                $where['user_id'] = $user['user_id'];
            }
            if ($st == 4) {
                $con = '平台用户名';
                $where['usernamep'] = $key;
            }
        }
        if (trim($_GET['time-start']) && trim($_GET['time-end'])) {
            $time_start = strtotime($_GET['time-start']);
            $time_end = strtotime($_GET['time-end']) + 3600 * 24;
            $where['plat.reg_time <= '] = $time_end;
            $where['plat.reg_time >= '] = $time_start;
        }
        
        if(isset($_GET['bind']) && $_GET['bind']){
            $is_bind = $_GET['bind'] == 1 ? 1 : 0;
            $where['is_data_bind'] = $is_bind;
            $this->template->assign('b', $_GET['bind']);
        }
        
        //分页
       $getcount = $this->plat_cpa_model->get_ac_cpa_count($where);
       $navigation_position = 'outside';
       $records_per_page = 10;
       $this->xpage->navigation_position(isset($navigation_position) && in_array($navigation_position, array('left', 'right')) ? $navigation_position : 'outside');
       //$this->xpage->reverse(true);
       $this->xpage->records($getcount);
       $this->xpage->records_per_page($records_per_page);
       $this->xpage->labels("<<", ">>");
       $list = $this->plat_cpa_model->get_ac_cpa_list($where, (($this->xpage->get_page() - 1) * $records_per_page) ,$records_per_page);
       foreach ($list as $key =>$val){
           $list[$key]['reg_time'] = date("Y-m-d H:i:s",$val['reg_time']);
       }
       //------------------
       $this->template->assign('stname', $st);
        $this->template->assign('keyname', trim($_GET['key']));
        $this->template->assign('conname', $con);
        $this->template->assign('time_start', trim($_GET['time-start']));
        $this->template->assign('time_end', trim($_GET['time-end']));
       $this->template->assign('Total',$getcount);
       $this->template->assign('showpage',$this->xpage->render(true));
        $this->template->assign('list',$list);
        $this->template->load('platforms/bindac');
    }
    //AC平台用户投资记录
    function investac(){
        $where = array();
        $st = trim($_GET['st']);
        $key = trim($_GET['key']);
        if ($key != '') {
            if ($st == 1) {
                $con = '平台中文名称';
                $plat = $this->plat_model->get(array('name_ch'=>$key));
                $where['plat_invest_list.plat_en'] = $plat['name_en'];
            }
            if ($st == 2) {
                $con = '平台英文名称';
                $plat = $this->plat_model->get(array('name_en'=>$key));
                $where['plat_invest_list.plat_en'] = $plat['name_en'];
            }
            if ($st == 3) {
                $con = '用户名';
                $user = $this->users_model->get_user_by_username($key);
                $where['plat_invest_list.user_id'] = $user['user_id'];
            }
        }
        if (trim($_GET['time-start']) && trim($_GET['time-end'])) {
            $time_start = strtotime($_GET['time-start']);
            $time_end = strtotime($_GET['time-end']) + 3600 * 24;
            $where['plat_invest_list.invest_time <= '] = $time_end;
            $where['plat_invest_list.invest_time >= '] = $time_start;
        }
        //分页
       $getcount = $this->plat_invest_model->get_invest_count($where);
       $navigation_position = 'outside';
       $records_per_page = 10;
       $this->xpage->navigation_position(isset($navigation_position) && in_array($navigation_position, array('left', 'right')) ? $navigation_position : 'outside');
       //$this->xpage->reverse(true);
       $this->xpage->records($getcount);
       $this->xpage->records_per_page($records_per_page);
       $this->xpage->labels("<<", ">>");
       $list = $this->plat_invest_model->get_invest_list($where, (($this->xpage->get_page() - 1) * $records_per_page) ,$records_per_page);
       $total_amount = $this->plat_invest_model->get_invest_total_amount($where);
       foreach ($list as $key =>$val){
           $cpa = $this->plat_cpa_model->get_ab_user_info(array('user_id'=>$val['user_id'],'plat_en'=>$val['plat_en']));
           $list[$key]['usernamep'] = $cpa['usernamep'];
           $list[$key]['amount'] = sprintf("%0.2f",$val['amount']);
           $list[$key]['unit'] = $val['unit'] == 1 ? "天" : "月";
           $list[$key]['invest_time'] = date("Y-m-d H:i:s",$val['invest_time']);
           $list[$key]['period_'] = $this->plat_period[$val['plat_period']];
       }
       //------------------
        $this->template->assign('stname', $st);
        $this->template->assign('keyname', trim($_GET['key']));
        $this->template->assign('conname', $con);
        $this->template->assign('time_start', trim($_GET['time-start']));
        $this->template->assign('time_end', trim($_GET['time-end']));
        $this->template->assign('Total',$getcount);
        $this->template->assign('showpage',$this->xpage->render(true));
        $this->template->assign('list',$list);
        $this->template->assign('total_amount',$total_amount);
        $this->template->load('platforms/investac');
    }
    //线下投资管理
    function investline(){
        $where = array();
        $st = trim($_GET['st']);
        $key = trim($_GET['key']);
        if ($key != '') {
            if ($st == 1) {
                $con = '平台中文名称';
                $plat = $this->plat_model->get(array('name_ch'=>$key));
                $where['plat_invest_list_line.plat_en'] = $plat['name_en'];
            }
            if ($st == 2) {
                $con = '平台英文名称';
                $plat = $this->plat_model->get(array('name_en'=>$key));
                $where['plat_invest_list_line.plat_en'] = $plat['name_en'];
            }
            if ($st == 3) {
                $con = '平台用户名';
                $where['plat_invest_list_line.usernamep'] = $key;
            }
        }
        if (trim($_GET['time-start']) && trim($_GET['time-end'])) {
            $time_start = strtotime($_GET['time-start']);
            $time_end = strtotime($_GET['time-end']) + 3600 * 24;
            $where['plat_invest_list_line.invest_time <= '] = $time_end;
            $where['plat_invest_list_line.invest_time >= '] = $time_start;
        }
        //分页
       $getcount = $this->plat_invest_model->get_invest_line_count($where);
       $navigation_position = 'outside';
       $records_per_page = 10;
       $this->xpage->navigation_position(isset($navigation_position) && in_array($navigation_position, array('left', 'right')) ? $navigation_position : 'outside');
       $this->xpage->records($getcount);
       $this->xpage->records_per_page($records_per_page);
       $this->xpage->labels("<<", ">>");
       $list = $this->plat_invest_model->get_invest_line_list($where, (($this->xpage->get_page() - 1) * $records_per_page) ,$records_per_page);
       $total_amount = $this->plat_invest_model->get_invest_line_total_amount($where);
       foreach ($list as $key =>$val){
           $total_amount += $val['amount'];
           $list[$key]['amount'] = sprintf("%0.2f",$val['amount']);
           $list[$key]['unit'] = $val['unit'] == 1 ? "天" : "月";
           $list[$key]['invest_time'] = date("Y-m-d H:i:s",$val['invest_time']);
       }
       //------------------
        $this->template->assign('stname', $st);
        $this->template->assign('keyname', trim($_GET['key']));
        $this->template->assign('conname', $con);
        $this->template->assign('time_start', trim($_GET['time-start']));
        $this->template->assign('time_end', trim($_GET['time-end']));
        $this->template->assign('Total',$getcount);
        $this->template->assign('showpage',$this->xpage->render(true));
        $this->template->assign('list',$list);
        $this->template->assign('total_amount',$total_amount);
        $this->template->load('platforms/investline');
    }
    
    
    //AB平台用户绑定记录
    function bindab(){
        $where = array();
        $st = trim($_GET['st']);
        $key = trim($_GET['key']);
        if ($key != '') {
            if ($st == 1) {
                $con = '平台中文名称';
                $plat = $this->plat_model->get(array('name_ch'=>$key));
                $where['plat_en'] = $plat['name_en'];
            }
            if ($st == 2) {
                $con = '平台英文名称';
                $plat = $this->plat_model->get(array('name_en'=>$key));
                $where['plat_en'] = $plat['name_en'];
            }
            if ($st == 3) {
                $con = '用户名';
                $user = $this->users_model->get_user_by_username($key);
                $where['plat_ab_cpa.user_id'] = $user['user_id'];
            }
            if ($st == 4) {
                $con = '平台用户名';
                $where['usernamep'] = $key;
            }
        }
        if (trim($_GET['time-start']) && trim($_GET['time-end'])) {
            $time_start = strtotime($_GET['time-start']);
            $time_end = strtotime($_GET['time-end']) + 3600 * 24;
            $where['plat.reg_time <= '] = $time_end;
            $where['plat.reg_time >= '] = $time_start;
        }
        
        if(isset($_GET['bind']) && $_GET['bind']){
            $is_bind = $_GET['bind'] == 1 ? 1 : 0;
            $where['is_data_bind'] = $is_bind;
            $this->template->assign('b', $_GET['bind']);
        }
        
        //分页
       $getcount = $this->plat_cpa_model->get_ab_cpa_count($where);
       $navigation_position = 'outside';
       $records_per_page = 10;
       $this->xpage->navigation_position(isset($navigation_position) && in_array($navigation_position, array('left', 'right')) ? $navigation_position : 'outside');
       //$this->xpage->reverse(true);
       $this->xpage->records($getcount);
       $this->xpage->records_per_page($records_per_page);
       $this->xpage->labels("<<", ">>");
       $list = $this->plat_cpa_model->get_ab_cpa_list($where, (($this->xpage->get_page() - 1) * $records_per_page) ,$records_per_page);
       foreach ($list as $key =>$val){
           $list[$key]['reg_time'] = date("Y-m-d H:i:s",$val['reg_time']);
           $list[$key]['amount'] =  sprintf("%0.2f",$val['amount']);
           $list[$key]['period'] = $this->plat_period[$val['plat_period']];
       }
       
       //------------------
       $this->template->assign('stname', $st);
        $this->template->assign('keyname', trim($_GET['key']));
        $this->template->assign('conname', $con);
        $this->template->assign('time_start', trim($_GET['time-start']));
        $this->template->assign('time_end', trim($_GET['time-end']));
       $this->template->assign('Total',$getcount);
       $this->template->assign('showpage',$this->xpage->render(true));
        $this->template->assign('list',$list);
        $this->template->load('platforms/bindab');
    }
    
    function export_bindab(){
        $this->load->library('Export');
        $where = array();
        $st = trim($_GET['st']);
        $key = trim($_GET['key']);
        if ($key != '') {
            if ($st == 1) {
                $con = '平台中文名称';
                $plat = $this->plat_model->get(array('name_ch'=>$key));
                $where['plat_en'] = $plat['name_en'];
            }
            if ($st == 2) {
                $con = '平台英文名称';
                $plat = $this->plat_model->get(array('name_en'=>$key));
                $where['plat_en'] = $plat['name_en'];
            }
            if ($st == 3) {
                $con = '用户名';
                $user = $this->users_model->get_user_by_username($key);
                $where['plat_ab_cpa.user_id'] = $user['user_id'];
            }
            if ($st == 4) {
                $con = '平台用户名';
                $where['usernamep'] = $key;
            }
        }
        if (trim($_GET['time-start']) && trim($_GET['time-end'])) {
            $time_start = strtotime($_GET['time-start']);
            $time_end = strtotime($_GET['time-end']) + 3600 * 24;
            $where['plat.reg_time <= '] = $time_end;
            $where['plat.reg_time >= '] = $time_start;
        }
        
        if(isset($_GET['bind']) && $_GET['bind']){
            $is_bind = $_GET['bind'] == 1 ? 1 : 0;
            $where['is_data_bind'] = $is_bind;
            $this->template->assign('b', $_GET['bind']);
        }
        
        //分页
       $getcount = $this->plat_cpa_model->get_ab_cpa_count($where);
       $navigation_position = 'outside';
       $records_per_page = 10000;
       $this->xpage->navigation_position(isset($navigation_position) && in_array($navigation_position, array('left', 'right')) ? $navigation_position : 'outside');
       //$this->xpage->reverse(true);
       $this->xpage->records($getcount);
       $this->xpage->records_per_page($records_per_page);
       $this->xpage->labels("<<", ">>");
       $list = $this->plat_cpa_model->get_ab_cpa_list($where, (($this->xpage->get_page() - 1) * $records_per_page) ,$records_per_page);
       foreach ($list as $key =>$val){
           $invest = $this->plat_invest_model->get_plat_invest(array('plat_en'=>$val['plat_en'],'user_id'=>$val['user_id']));
           $list[$key]['reg_time'] = date("Y-m-d H:i:s",$val['reg_time']);
           $list[$key]['amount'] =  sprintf("%0.2f",$val['amount']);
           $list[$key]['is_data_bind'] = $val['is_data_bind'] == 1 ? "已认证" : "未认证";
           $list[$key]['bidnum'] = $invest['borrow_nid'];
           $list[$key]['title'] = $invest['title'];
           $list[$key]['invest_time'] = $invest ? date("Y-m-d H:i:s",$invest['invest_time']) : "";
       }
       $ListRowData = array();
       foreach ($list as $key=>$val){
            $temp = array();
            $temp[] = $val['name_ch'];
            $temp[] = $val['username'];
            $temp[] = $val['usernamep'];
            $temp[] = $val['reg_time'];
            $temp[] = $val['is_data_bind'];
            $temp[] = $val['amount'];
            $temp[] = $val['invest_time'];
            $temp[] = $val['bidnum'];
            $temp[] = $val['title'];
            $ListRowData[$key]['RowData'] = $temp;
        }
        $HeadData = array('平台名称',"用户名",'平台用户名',"注册时间","是否实名认证",'首投金额','首投时间','标的编号',"标的名称");
        $filename = $plat['name_ch'].'结算表（'.date('Y-m-d').")";
        echo $this->export->users($HeadData,$ListRowData,$filename);
       
    }
    
    //平台体验日志
    function platlog(){
        $where = array();
        $st = trim($_GET['st']);
        $key = trim($_GET['key']);
        if ($key != '') {
            if ($st == 1) {
                $con = '平台中文名称';
                $plat = $this->plat_model->get(array('name_ch'=>$key));
                $where['plat_log.plat_en'] = $plat['name_en'];
            }
            if ($st == 2) {
                $con = '平台英文名称';
                $plat = $this->plat_model->get(array('name_en'=>$key));
                $where['plat_log.plat_en'] = $plat['name_en'];
            }
            if ($st == 3) {
                $con = '用户名';
                $user = $this->users_model->get_user_by_username($key);
                $where['plat_log.user_id'] = $user['user_id'];
            }
        }
        if (trim($_GET['time-start']) && trim($_GET['time-end'])) {
            $time_start = strtotime($_GET['time-start']);
            $time_end = strtotime($_GET['time-end']) + 3600 * 24;
            $where['plat_log.create_time <= '] = $time_end;
            $where['plat_log.create_time >= '] = $time_start;
        }
        
        //分页
        $getcount = $this->plat_model->get_log_count($where);
        $navigation_position = 'outside';
        $records_per_page = $_GET['export'] ? 100000 : 10;
        $this->xpage->navigation_position(isset($navigation_position) && in_array($navigation_position, array('left', 'right')) ? $navigation_position : 'outside');
        //$this->xpage->reverse(true);
        $this->xpage->records($getcount);
        $this->xpage->records_per_page($records_per_page);
        $this->xpage->labels("<<", ">>");
        $list = $this->plat_model->get_log_list($where, (($this->xpage->get_page() - 1) * $records_per_page) ,$records_per_page);
        $award = 0;
        $true_award = 0;
        foreach ($list as $key =>$val){
            $list[$key]['create_time'] = date("Y-m-d H:i:s",$val['create_time']);
            if($val['is_add'] == 0){
                $award += $val['award'];
                $true_award += $val['true_award'];
            }
            $list[$key]['award'] = number_format($val['award']);
            $list[$key]['true_award'] = number_format($val['true_award']);
            $list[$key]['plat_balance'] = number_format($val['plat_balance']);
            $list[$key]['create_time'] = date("Y-m-d H:i:s",$val['create_time']);
            $list[$key]['period'] = $this->plat_period[$val['plat_period']];
        }
        if($_GET['export']){
            $this->load->library('Export');
            $ListRowData = array();
            foreach ($list as $key=>$val){
                 $temp = array();
                 $temp[] = $val['name_ch'];
                 $temp[] = $val['username'];
                 $temp[] = $val['award'];
                 $temp[] = $val['true_award'];
                 $temp[] = $val['plat_balance'];
                 $temp[] = $val['create_time'];
                 if($val['is_add'] == 0){
                     $ListRowData[]['RowData'] = $temp;
                 }
             }
             //标题名称
            $temp['RowData'] = array();
            $temp['RowData'][] = "弹溜溜平台用户体验日志明细表".  date('Y-m-d');
            array_push($ListRowData,$temp);
            //导出时间
            $temp = array();
            $temp['RowData'][] = "起始时间：".($_GET['time-start'] ? $_GET['time-start'] : date('Y-m-d'));
            $temp['RowData'][] = "结束时间：".($_GET['time-end'] ? $_GET['time-end'] : date('Y-m-d'));
            array_push($ListRowData,$temp);
            //总支出
            $temp['RowData'] = array();
            $temp['RowData'][] = "用户总返佣溜溜币：". $award;
            $temp['RowData'][] = "平台总返佣溜溜币：". $true_award;
            array_push($ListRowData,$temp);
            $HeadData = array('平台名称','用户名','用户返佣溜溜币','平台返佣溜溜币','平台预付剩余溜溜币','体验时间');
            $filename = '弹溜溜平台用户体验日志明细表'.date('Y-m-d');
            echo $this->export->users($HeadData,$ListRowData,$filename);exit;
        }
        //------------------
        $this->template->assign('stname', $st);
        $this->template->assign('keyname', trim($_GET['key']));
        $this->template->assign('conname', $con);
        $this->template->assign('time_start', trim($_GET['time-start']));
        $this->template->assign('time_end', trim($_GET['time-end']));
        $this->template->assign('Total',$getcount);
        $this->template->assign('showpage',$this->xpage->render(true));
        $this->template->assign('list',$list);
        $this->template->load('platforms/platlog');
    }
    
    //商务合作平台
    function cooperation(){
        $where = array();
        
        //是否联系
        if($_GET['type']){
            $type = $_GET['type'] == 1 ? 1 : 0;
            $where['is_call'] = $type;
        }
        
        if($_GET['key']){
            $keyword = $_GET['key'];
            $like = $keyword ? $keyword : '';
        }
        
        if (trim($_GET['time-start']) && trim($_GET['time-end'])) {
            $time_start = strtotime($_GET['time-start']);
            $time_end = strtotime($_GET['time-end']) + 3600 * 24;
            $where['create_time <= '] = $time_end;
            $where['create_time >= '] = $time_start;
        }
        //分页
        $getcount = $this->plat_model->get_cooperation_count($where,$like);
        $navigation_position = 'outside';
        $records_per_page = 10;
        $this->xpage->navigation_position(isset($navigation_position) && in_array($navigation_position, array('left', 'right')) ? $navigation_position : 'outside');
        //$this->xpage->reverse(true);
        $this->xpage->records($getcount);
        $this->xpage->records_per_page($records_per_page);
        $this->xpage->labels("<<", ">>");
        $list = $this->plat_model->get_cooperation_list($where, (($this->xpage->get_page() - 1) * $records_per_page) ,$records_per_page,$like);
        foreach ($list as $key =>$val){
            $list[$key]['create_time'] = date("Y-m-d H:i:s",$val['create_time']);
            if(!strstr($val['website'], 'http')){
                $list[$key]['website'] = 'http://'.$val['website'];
            }
        }
        $this->template->assign('tt', $_GET['type']);
        $this->template->assign('keyname', $keyword);
        $this->template->assign('time_start', trim($_GET['time-start']));
        $this->template->assign('time_end', trim($_GET['time-end']));
        $this->template->assign('Total',$getcount);
        $this->template->assign('showpage',$this->xpage->render(true));
        $this->template->assign('list',$list);
        $this->template->load('platforms/cooperation');
    }
    
    function setcall(){
        if($_GET){
            $mssage = array();
            $plat_id	   = trim($_GET['id']);
            $is_show = trim($_GET['is_call']);
            $data = array();
            $data['is_call'] = $is_show;
            $result = $this->plat_model->update_plat_cooperation($data,$plat_id);
            if($result){
                $mssage['info']	  = '设置成功';
                $mssage['status'] = 1;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }else{
                $mssage['info']	  = '操作失败';
                $mssage['status'] = 0;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }

        }
    }
    
    function c_delete(){
        if($_GET){
            $mssage = array();
            $plat_id	   = trim($_GET['id']);
            $data = array();
            $result = $this->plat_model->delete_cooperation($plat_id);
            if($result){
                $mssage['info']	  = '删除成功';
                $mssage['status'] = 1;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }else{
                $mssage['info']	  = '操作失败';
                $mssage['status'] = 0;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }

        }
    }
    
    //导出投资表
    function export_invest(){
        $this->load->library('Export');
        
        $where = array();
        $st = trim($_GET['st']);
        $key = trim($_GET['key']);
        if ($key != '') {
            if ($st == 1) {
                $con = '平台中文名称';
                $plat = $this->plat_model->get(array('name_ch'=>$key));
                $where['plat_invest_list.plat_en'] = $plat['name_en'];
            }
            if ($st == 2) {
                $con = '平台英文名称';
                $plat = $this->plat_model->get(array('name_en'=>$key));
                $where['plat_invest_list.plat_en'] = $plat['name_en'];
            }
            if ($st == 3) {
                $con = '用户名';
                $user = $this->users_model->get_user_by_username($key);
                $where['plat_invest_list.user_id'] = $user['user_id'];
            }
        }
        if (trim($_GET['time-start']) && trim($_GET['time-end'])) {
            $time_start = strtotime($_GET['time-start']);
            $time_end = strtotime($_GET['time-end']) + 3600 * 24;
            $where['plat_invest_list.invest_time <= '] = $time_end;
            $where['plat_invest_list.invest_time >= '] = $time_start;
        }
        //分页
       $getcount = $this->plat_invest_model->get_invest_count($where);
       $navigation_position = 'outside';
       $records_per_page = 10000;
       $this->xpage->navigation_position(isset($navigation_position) && in_array($navigation_position, array('left', 'right')) ? $navigation_position : 'outside');
       //$this->xpage->reverse(true);
       $this->xpage->records($getcount);
       $this->xpage->records_per_page($records_per_page);
       $this->xpage->labels("<<", ">>");
       $list = $this->plat_invest_model->get_invest_list($where, (($this->xpage->get_page() - 1) * $records_per_page) ,$records_per_page);
//       p($list);die;
       foreach ($list as $key =>$val){
           $cpa = $this->plat_cpa_model->get_ab_user_info(array('user_id'=>$val['user_id'],'plat_id'=>$val['plat_id']));
           $list[$key]['usernamep'] = $cpa['usernamep'];
           $list[$key]['amount'] = sprintf("%0.2f",$val['amount']);
           $list[$key]['unit'] = $val['unit'] == 1 ? "天" : "月";
           $list[$key]['invest_time'] = date("Y-m-d H:i:s",$val['invest_time']);
       }
       $ListRowData = array();
       
       foreach ($list as $key=>$val){
            $temp = array();
            $temp[] = $val['name_ch'];
            $temp[] = $val['username'];
            $temp[] = $val['usernamep'];
            $temp[] = $val['borrow_nid'];
            $temp[] = $val['title'];
            $temp[] = sprintf('%0.2f',$val['amount']);
            $temp[] = $val['period'];
            $temp[] = $val['unit'];
            $temp[] = sprintf('%0.2f',$val['rate']).'%';
            $temp[] = $val['invest_time'];
            $ListRowData[$key]['RowData'] = $temp;
        }
        
        $HeadData = array('平台名称',"用户名",'平台用户名','标的编号','标的标题','投资金额（元）','期限','期限单位','年利率','投资时间');
        $filename = $plat['name_ch'].'结算表（'.date('Y-m-d').")";
        echo $this->export->users($HeadData,$ListRowData,$filename);
    }
    
    //体验奖励管理
    function award(){
        $where = array();
        $st = trim($_GET['st']);
        $key = trim($_GET['key']);
        if ($key != '') {
            if ($st == 1) {
                $con = '平台中文名称';
                $plat = $this->plat_model->get(array('name_ch'=>$key));
                $where['plat_award_list.plat_en'] = $plat['name_en'];
            }
            if ($st == 2) {
                $con = '平台英文名称';
                $plat = $this->plat_model->get(array('name_en'=>$key));
                $where['plat_award_list.plat_en'] = $plat['name_en'];
            }
            if ($st == 3) {
                $con = '用户名';
                $user = $this->users_model->get_user_by_username($key);
                $where['plat_award_list.user_id'] = $user['user_id'];
            }
        }
        if (trim($_GET['time-start']) && trim($_GET['time-end'])) {
            $time_start = strtotime($_GET['time-start']);
            $time_end = strtotime($_GET['time-end']) + 3600 * 24;
            $where['plat_award_list.create_time <= '] = $time_end;
            $where['plat_award_list.create_time >= '] = $time_start;
        }
        
        if(isset($_GET['is_receive']) && $_GET['is_receive']){
            $is_bind = $_GET['is_receive'] == 1 ? 1 : 0;
            $where['is_receive'] = $is_bind;
            $this->template->assign('b', $_GET['is_receive']);
        }
        
        //分页
       $getcount = $this->plat_award_list_model->getCount($where);
       $navigation_position = 'outside';
       $records_per_page = 10;
       $this->xpage->navigation_position(isset($navigation_position) && in_array($navigation_position, array('left', 'right')) ? $navigation_position : 'outside');
       //$this->xpage->reverse(true);
       $this->xpage->records($getcount);
       $this->xpage->records_per_page($records_per_page);
       $this->xpage->labels("<<", ">>");
       $list = $this->plat_award_list_model->getList($where, (($this->xpage->get_page() - 1) * $records_per_page) ,$records_per_page);
       foreach ($list as $key =>$val){
           $cpa = $this->plat_cpa_model->get_ab_user_info(array('user_id'=>$val['user_id'],'plat_id'=>$val['plat_id']));
           $list[$key]['usernamep'] = $cpa['usernamep'];
           $list[$key]['rule_step'] = "第".$val['rule_step']."步";
           $list[$key]['award'] = number_format($val['award']);
           $list[$key]['exper'] = number_format($val['exper']);
           $list[$key]['create_time'] = date("Y-m-d H:i:s",$val['create_time']);
           $list[$key]['period'] = $this->plat_period[$val['plat_period']];
       }
       //------------------
       $this->template->assign('stname', $st);
        $this->template->assign('keyname', trim($_GET['key']));
        $this->template->assign('conname', $con);
        $this->template->assign('time_start', trim($_GET['time-start']));
        $this->template->assign('time_end', trim($_GET['time-end']));
       $this->template->assign('Total',$getcount);
       $this->template->assign('showpage',$this->xpage->render(true));
        $this->template->assign('list',$list);
        $this->template->load('platforms/award');
    }
    
    //自动领取体验奖励
    function recieve_award(){
        $award_id = isset($_REQUEST['id']) ? $_REQUEST['id'] : 0;
        $award = $this->plat_award_list_model->get(array("id"=>  intval($award_id),"is_receive"=>0));
        if(!$award){
            $mssage['info']	  = '没有找到该条记录或已被处理';
            $mssage['status'] = 0;
            $mssage['url']	  = $_SERVER['HTTP_REFERER'];
            echo json_encode($mssage);exit;
        }
        $exper_award = $this->config_award['exper_award'];
        $plat = $this->plat_model->get(array('id'=>$award['plat_id']));
        $user = $this->users_model->get_user_by_uid($award['user_id']);
        $msg_finance = '';
        $msg_experience = '';
        $award_finance = $award['award'];
        $award_experience = $award['exper'];

        $msg_finance = '体验'.$plat['name_ch'].'第'.$award['rule_step'].'步，奖励'.$award_finance.'溜溜币';
        $msg_experience = '体验'.$plat['name_ch'].'第'.$award['rule_step'].'步，奖励'.$award_experience.'积分';

        //vip奖励
        $exper_award = $exper_award[$user['vip_degree']];
        if($exper_award){
            $vip_award = $award['award'] * $exper_award;$vip_award = $vip_award ? $vip_award : 0;//vip溜溜币奖励
            $vip_exper = $award['exper'] * $exper_award;$vip_exper = $vip_exper ? $vip_exper : 0;//vip积分奖励
            $msg_finance .= "，vip额外奖励".$vip_award.'溜溜币';
            $msg_experience .= "，vip额外奖励".$vip_exper."积分";
        }
        $data = array();
        $data['is_receive'] = 1;
        $result = $this->plat_award_list_model->update($data,$award_id);
        if($result){
            //完成新手任务第三步
            $count = $this->plat_award_list_model->getCount(array('user_id'=>$user['user_id'],'rule_step'=>1,'is_receive'=>1));
            if($award['rule_step'] == 1 && $count == 1){//
                $this->new_task_model->update(array('is_finish'=>1,'finish_time'=>  time()),array('user_id'=>$user['user_id'],'step'=>3));
                $new_task = $this->config_task['new_task'][2];
                $message = "恭喜您完成新手任务第三步【".$new_task['title']."】,奖励您<span class='mail-award'>".$new_task['award_finance']."溜溜币</span>和<span class='mail-award'>".$new_task['award_experience']."积分</span>，赶快去<a href='/mtask.html' target='_blank' class='mail-award-a'>立即领取&gt;&gt;</a>吧。感谢您对弹溜溜的支持！";
                $message = mail_notice_tpl($this->config_tpl['mail_tpl'], $message);
                $this->db->insert("users_award_notice", array('user_id'=>$user['user_id'],'title'=>'任务通知','content'=>$message,'from'=>'弹溜溜官方','create_time'=>  time()));
            }
//            //获取账户信息
            $account = $this->account_model->get($user['user_id']);
            $account_data = array();
            $account_data['total'] = $account['total']+ $award_finance + $vip_award;//账户总额
            $account_data['balance'] = $account['balance'] + $award_finance + $vip_award;//账户余额
            $account_data['experience'] = $account['experience'] + $award_experience + $vip_exper;//当前积分值
            $account_data['experience_balance'] = $account['experience_balance'] +  $award_experience + $vip_exper;//可用积分值
            //更新账户
            $this->account_model->update($account_data,$user['user_id']);
            //写入溜溜币明细
            $finance_list_data = array();
            $finance_list_data['user_id'] = $user['user_id'];
            $finance_list_data['content'] = $msg_finance;
            $finance_list_data['finance'] = $award_finance + $vip_award;
            $finance_list_data['finance_balance'] = $account_data['balance'];
            $finance_list_data['reward_type'] = 'exper_award';
            $finance_list_data['type'] = 1;
            $finance_list_data['create_time'] = time();
            $finance_list_data['month'] = date("Ym");
            $finance_list_data['day'] = date("Ymd");
            $this->finance_list_model->insert($finance_list_data);
            if($award_experience){
                //写入积分明细
                $experience_list_data = array();
                $experience_list_data['user_id'] = $user['user_id'];
                $experience_list_data['content'] = $msg_experience;
                $experience_list_data['experience'] = $award_experience + $vip_exper;
                $experience_list_data['experience_balance'] = $account_data['experience_balance'];
                $experience_list_data['reward_type'] = 'exper_award';
                $experience_list_data['type'] = 1;
                $experience_list_data['create_time'] = time();
                $experience_list_data['month'] = date("Ym");
                $experience_list_data['day'] = date("Ymd");
                $this->experience_list_model->insert($experience_list_data);
            }
            //日志
            $log_data = array();
            $log_data['user_id'] = $user['user_id'];
            $log_data['events'] = 'receive_award';
            $log_data['content'] = '领取体验奖励';
            $log_data['ip'] = $this->input->ip_address();
            $log_data['create_time'] = time();
            $this->users_log_model->insert($log_data);
            
            $mssage['info']	  = '领取成功';
            $mssage['status'] = 1;
            $mssage['url']	  = $_SERVER['HTTP_REFERER'];
            echo json_encode($mssage);exit;
        }else{
            $mssage['info']	  = '领取失败';
            $mssage['status'] = 0;
            $mssage['url']	  = $_SERVER['HTTP_REFERER'];
            echo json_encode($mssage);exit;
        }
    }
    
    //导入线下投资数据
    function import_line_invest(){
        $mess = array();
        if($_POST){
            $my_excel = new Mexcel();
            $file_name = trim($_POST['file_url']);
            $result = $my_excel->excel_to_array($file_name);
            if($result['status'] == 1 ){
                $list_ = $result['data'];
                if(!$list_){
                    $mess['status'] = 1;
                    $mess['error'] = '没有发现任何数据';
                    echo json_encode($mess);die;
                }
                $list = array();
                foreach ($list_ as $key=>$val){
                    $temp = array();
                    $temp['plat_id'] = $val[0];
                    $temp['plat_en'] = $val[1];
                    $temp['usernamep'] = $val[2];
                    $temp['borrow_nid'] = $val[3];
                    $temp['title'] = $val[4];
                    $temp['url'] = $val[5];
                    $temp['amount'] = $val[6];
                    $temp['period'] = $val[7];
                    $temp['unit'] = $val[8] == '月' ? 2 : 1;
                    $temp['rate'] = $val[9];
                    $temp['invest_time'] = strtotime($val[10]);
                    $temp['create_time'] = time();
                    $list[] = $temp;
                }
                $this->plat_invest_model->insert_batch($list);
                $mess['status'] = 0;
                $mess['error'] = "导入成功";
            }else{
                $mess['status'] = 1;
                $mess['error'] = $result['error'];
            }
            echo json_encode($mess);die;
        }
    }
    //平台分类管理
    function platcates(){
        $where = array();
        $list = $this->db->query("select * from tan_plat_category where pid = 0 order by sort desc limit 10")->result_array();
        $this->template->assign('list',$list);
        $this->template->load('platforms/platcates');
    }
    //添加平台分类
    public function platcates_add(){
        if($_POST){
            $data = array();
            $data['title'] = trim($_POST['title']);
            $data['code'] = trim($_POST['code']);
            $data['sort'] = trim($_POST['sort']);
            $data['desc'] = trim($_POST['desc']);
            $data['is_hide'] = trim($_POST['is_hide']);
            $data['groups'] = $data['code'];
            $data['pid'] = 0;
            $data['level'] = 0;
            if(!$data['title']){
                $mssage['info']	  = '类别名称不能为空';
                $mssage['status'] = 0;
                $mssage['url']	  = "";
                echo json_encode($mssage);exit;
            }
            
            if(!$data['code']){
                $mssage['info']	  = '类别标识不能为空';
                $mssage['status'] = 0;
                $mssage['url']	  = "";
                echo json_encode($mssage);exit;
            }
            
            $temp = $this->db->query("select * from tan_plat_category where code = '$data[code]' limit 1")->row_array();
            if($temp){
                $mssage['info']	  = '类别标识不能重复';
                $mssage['status'] = 0;
                $mssage['url']	  = "";
                echo json_encode($mssage);exit;
            }
            
            $result = $this->db->insert("tan_plat_category",$data);
            if($result){
                $mssage['info']	  = '添加成功';
                $mssage['status'] = 1;
                $mssage['url']	  = site_url('platforms/platcates');
                echo json_encode($mssage);exit;
            }else{
                $mssage['info']	  = '添加失败';
                $mssage['status'] = 0;
                $mssage['url']	  = site_url('platforms/platcates');
                echo json_encode($mssage);exit;
            }
            
        }
        $this->template->assign('segment_p','platcates');
        $this->template->load('platforms/platcates_add');
    }
    //修改平台分类
    public function platcates_edit(){
        if($_POST){
            $id = trim($_POST['id']);
            $data = array();
            $data['title'] = trim($_POST['title']);
            $data['desc'] = trim($_POST['desc']);
            $data['sort'] = trim($_POST['sort']);
            $data['is_hide'] = trim($_POST['is_hide']);
            if(!$data['title']){
                $mssage['info']	  = '类别名称不能为空';
                $mssage['status'] = 0;
                $mssage['url']	  = "";
                echo json_encode($mssage);exit;
            }
            
            $result = $this->db->where("id",$id)->update("tan_plat_category",$data);
            if($result){
                $mssage['info']	  = '修改成功';
                $mssage['status'] = 1;
                $mssage['url']	  = site_url('platforms/platcates');
                echo json_encode($mssage);exit;
            }else{
                $mssage['info']	  = '修改失败';
                $mssage['status'] = 0;
                $mssage['url']	  = site_url('platforms/platcates');
                echo json_encode($mssage);exit;
            }
            
        }
        $id = isset($_GET['id']) ? trim($_GET['id']) : 0;
        $item = $this->db->query("select * from tan_plat_category where id = $id order by id desc limit 1")->row_array();
        if(!$item){redirect("platforms/platcates");}
        $this->template->assign('item',$item);
        $this->template->assign('segment_p','platcates');
        $this->template->load('platforms/platcates_edit');
    }
    //子分类列表
    function platcates_son(){
        $pid = trim($_GET['pid']);
        if(!$pid){
            redirect("platforms/platcates");
        }
        $where = "pid = $pid";
        $getcount = $this->db->query("select * from tan_plat_category where $where ")->num_rows();
        $navigation_position = 'outside';
        $records_per_page = 10;
        $this->xpage->navigation_position(isset($navigation_position) && in_array($navigation_position, array('left', 'right')) ? $navigation_position : 'outside');
        //$this->xpage->reverse(true);
        $this->xpage->records($getcount);
        $this->xpage->records_per_page($records_per_page);
        $this->xpage->labels("<<", ">>");
        $list = $this->db->query("select * from tan_plat_category where $where order by sort desc limit ". (($this->xpage->get_page() - 1) * $records_per_page).",".$records_per_page)->result_array();
        
        $item = $this->db->query("select * from tan_plat_category where id = $pid order by id desc limit 1")->row_array();
        $this->template->assign('item',$item);
        $this->template->assign('list',$list);
        $this->template->assign('Total',$getcount);
        $this->template->assign('showpage',$this->xpage->render(true));
        $this->template->assign('segment_p','platcates');
        $this->template->load('platforms/platcates_son');
    }
    
    //添加子分类
    function platcates_son_add(){
        if($_POST){
            $data = array();
            $data['title'] = trim($_POST['title']);
            $data['code'] = "";
            $data['desc'] = trim($_POST['desc']);
            $data['groups'] = trim($_POST['groups']);
            $data['pid'] = trim($_POST['pid']);
            $data['is_hide'] = trim($_POST['is_hide']);
            $data['sort'] = trim($_POST['sort']);
            $data['level'] = trim($_POST['level']) + 1;
            if(!$data['title']){
                $mssage['info']	  = '类别名称不能为空';
                $mssage['status'] = 0;
                $mssage['url']	  = "";
                echo json_encode($mssage);exit;
            }
            
            $result = $this->db->insert("tan_plat_category",$data);
            if($result){
                update_cache("platcate");
                
                $mssage['info']	  = '添加成功';
                $mssage['status'] = 1;
                $mssage['url']	  = site_url('platforms/platcates_son')."?pid=".$data['pid'];
                echo json_encode($mssage);exit;
            }else{
                $mssage['info']	  = '添加失败';
                $mssage['status'] = 0;
                $mssage['url']	  = site_url('platforms/platcates_son')."?pid=".$data['pid'];
                echo json_encode($mssage);exit;
            }
            
        }
        $pid = isset($_GET['pid']) ? trim($_GET['pid']) : 0;
        $item = $this->db->query("select * from tan_plat_category where id = $pid order by id desc limit 1")->row_array();
        if(!$item){
            redirect("platforms/platcates");
        }
        $this->template->assign('item',$item);
        $this->template->assign('segment_p','platcates');
        $this->template->load('platforms/platcates_son_add');
    }
    //修改子分类信息
    function platcates_son_edit(){
        if($_POST){
            $data = array();
            $id = trim($_POST['id']);
            $pid = trim($_POST["pid"]);
            $data['desc'] = trim($_POST['desc']);
            $data['title'] = trim($_POST['title']);
            $data['is_hide'] = trim($_POST['is_hide']);
            $data['sort'] = trim($_POST['sort']);
            if(!$data['title']){
                $mssage['info']	  = '类别名称不能为空';
                $mssage['status'] = 0;
                $mssage['url']	  = "";
                echo json_encode($mssage);exit;
            }
            
            $result = $this->db->where("id",$id)->update("tan_plat_category",$data);
            if($result){
                update_cache("platcate");
                $mssage['info']	  = '添加成功';
                $mssage['status'] = 1;
                $mssage['url']	  = site_url('platforms/platcates_son')."?pid=".$pid;
                echo json_encode($mssage);exit;
            }else{
                $mssage['info']	  = '添加失败';
                $mssage['status'] = 0;
                $mssage['url']	  = site_url('platforms/platcates_son')."?pid=".$pid;
                echo json_encode($mssage);exit;
            }
            
        }
        $id = isset($_GET['id']) ? trim($_GET['id']) : 0;
        $item = $this->db->query("select * from tan_plat_category where id = $id order by id desc limit 1")->row_array();
        if(!$item){
            $url = site_url("platforms/platcates_son")."?pid=".$_GET['pid'];
            redirect($url);
        }
        $this->template->assign('item',$item);
        $this->template->assign('segment_p','platcates');
        $this->template->load('platforms/platcates_son_edit');
    }
    //删除子分类
    function platcates_son_del(){
        if($_GET){
            $mssage = array();
            $category_id	   = trim($_GET['id']);
            $this->db->where("id",$category_id)->delete("tan_plat_category");
            $result = $this->db->affected_rows();
            if($result){
                update_cache("platcate");
                $mssage['info']	  = '删除成功';
                $mssage['status'] = 1;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }else{
                $mssage['info']	  = '操作失败';
                $mssage['status'] = 0;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }

        }
    }
    
    function setplatcates_hide(){
        if($_GET){
            $mssage = array();
            $category_id	   = trim($_GET['id']);
            $is_hide = trim($_GET['is_hide']);
            $data = array();
            $data['is_hide'] = $is_hide;
            $result = $this->db->where("id",$category_id)->update("tan_plat_category",$data);
            if($result){
                update_cache("platcate");
                if($is_hide==1){
                    $mssage['info']	  = '显示成功';
                }else{
                    $mssage['info']	  = '隐藏成功';
                }
                $mssage['status'] = 1;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }else{
                $mssage['info']	  = '操作失败';
                $mssage['status'] = 0;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }

        }
    }
    //平台分类设置
    function cateset(){
        $where = array();
        if(isset($_REQUEST['key']) && trim($_REQUEST['key'])){
            $keyword = trim($_REQUEST['key']);
            $where['i.plat_ch'] = $keyword;
        }
        $getcount = $this->db->select("i.*")->from("tan_plat_info i")->where($where)->get()->num_rows();
        $navigation_position = 'outside';
        $records_per_page = 10;
        $this->xpage->navigation_position(isset($navigation_position) && in_array($navigation_position, array('left', 'right')) ? $navigation_position : 'outside');
        $this->xpage->records($getcount);
        $this->xpage->records_per_page($records_per_page);
        $this->xpage->labels("<<", ">>");
        $this->db->select('i.id,i.plat_en,i.plat_ch,c1.title bg_title,c2.title income_title,c3.title interest_title,c4.title province_title,c5.title zczj_title,c6.title online_title,c7.title business_title,c8.title zjtg_title');
                $this->db->from("tan_plat_info i");
                $this->db->join("tan_plat_category c1","c1.id = i.bg_type","left");//背景类型
                $this->db->join("tan_plat_category c2","c2.id = i.income_type","left");//平均收益
                $this->db->join("tan_plat_category c3","c3.id = i.interest_type","left");//溜溜加息
                $this->db->join("tan_plat_category c4","c4.id = i.province_type","left");//所在身份
                $this->db->join("tan_plat_category c5","c5.id = i.zczj_type","left");//注册资金
                $this->db->join("tan_plat_category c6","c6.id = i.online_type","left");//上线时间
                $this->db->join("tan_plat_category c7","c7.id = i.business_type","left");//业务类型
                $this->db->join("tan_plat_category c8","c8.id = i.zjtg_type","left");//资金托管
                $this->db->where($where);
                $this->db->limit($records_per_page, (($this->xpage->get_page() - 1) * $records_per_page));
                $this->db->order_by('i.id desc');
        $list = $this->db->get()->result_array(); 
                
        $this->template->assign('list',$list);
        $this->template->assign('Total',$getcount);
        $this->template->assign('keyname',$keyword);
        $this->template->assign('showpage',$this->xpage->render(true));
        $this->template->assign('segment_p','cateset');
        $this->template->load('platforms/cateset');
    }
    
    //平台类型设置修改
    function cateset_edit(){
        if($_POST){
            $id = trim($_POST['id']);
            $data = array();
            $data['bg_type'] = trim($_POST['bg_type']);
            $data['income_type'] = trim($_POST['income_type']);
            $data['interest_type'] = trim($_POST['interest_type']);
            $data['province_type'] = trim($_POST['province_type']);
            $data['zczj_type'] = trim($_POST['zczj_type']);
            $data['online_type'] = trim($_POST['online_type']);
            $data['business_type'] = trim($_POST['business_type']);
            $data['zjtg_type'] = trim($_POST['zjtg_type']);
            
            $result = $this->db->where(array("id"=>$id))->update("tan_plat_info",$data);
            if($result){
                update_cache("platlist");
                $mssage['info']	  = '更新成功';
                $mssage['status'] = 1;
                $mssage['url']	  = site_url("platforms/cateset");
                echo json_encode($mssage);exit;
            }else{
                $mssage['info']	  = '更新失败';
                $mssage['status'] = 0;
                $mssage['url']	  = site_url("platforms/cateset");
                echo json_encode($mssage);exit;
            }
        }
        
        $this->settings->load('platcate');
        $this->plat_category = setting("platcate");
        $bg_type = $this->plat_category['bg_type']['children'];
        $income_type = $this->plat_category['income_type']['children'];
        $interest_type = $this->plat_category['interest_type']['children'];
        $province_type = $this->plat_category['province_type']['children'];
        $zczj_type = $this->plat_category['zczj_type']['children'];
        $online_type = $this->plat_category['online_type']['children'];
        $business_type = $this->plat_category['business_type']['children'];
        $zjtg_type = $this->plat_category['zjtg_type']['children'];
        
        $plat_en= isset($_GET['key']) ? trim($_GET['key']) : 0;
        $item = $this->db->query("select id,plat_en,plat_ch,bg_type,income_type,interest_type,province_type,zczj_type,online_type,business_type,zjtg_type from tan_plat_info where plat_en = '$plat_en' order by id desc limit 1")->row_array();
        if(!$item){
            redirect("platforms/cateset");
        }
        
        $this->template->assign('bg_type',$bg_type);
        $this->template->assign('income_type',$income_type);
        $this->template->assign('interest_type',$interest_type);
        $this->template->assign('province_type',$province_type);
        $this->template->assign('zczj_type',$zczj_type);
        $this->template->assign('online_type',$online_type);
        $this->template->assign('business_type',$business_type);
        $this->template->assign('zjtg_type',$zjtg_type);
        $this->template->assign('item',$item);
        $this->template->assign('segment_p','index');
        $this->template->load('platforms/cateset_edit');
    }
}
